'use strict';

/**
 * @description 角色和菜单关系表模型
 * */
module.exports = app => {
  const { INTEGER } = app.Sequelize;

  const UserAndRole = app.model.define('userAndRole', {
    uid: {
      type: INTEGER,
      allowNull: false,
      comment: '用户id',
    },
    rid: {
      type: INTEGER,
      allowNull: false,
      comment: '角色id',
    },
  });

  UserAndRole.associate = () => {
    app.model.UserAndRole.belongsTo(app.model.User, {
      foreignKey: 'uid',
    });
    app.model.UserAndRole.belongsTo(app.model.Role, {
      foreignKey: 'rid',
    });
  };

  return UserAndRole;
};
